<%@ page language="java" contentType="text/html;charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<jsp:include page="../common/common.jsp" />
</head>
<body class="page-header-fixed">
	<jsp:include page="../common/header.jsp" />
	<div class="clearfix"></div>
	<div class="page-container">
		<div class="page-sidebar-wrapper"><jsp:include
				page="../common/menu.jsp" /></div>
		<div class="page-content-wrapper">
			<div class="page-content">
				<div class="row">
					<div class="col-md-12">
						<form class="form-horizontal form-row-seperated" id="formid"
							action="${path}/communication/save" method="post">
							<div class="portlet box purple">
								<div class="portlet-title">
									<div class="caption">
										<i class="fa fa-shopping-cart"></i>详细信息
									</div>
									<div class="actions btn-set">
										<a href="javascript:history.go(-1);" class="btn default"><i
											class="fa fa-angle-left" title="返回">返回</i></a> <a
											href="javascript:location.reload();" class="btn green"><i
											class="fa fa-reply" title="重置">重置</i></a>
										<button type="button" class="btn blue save"  onclick="save()">
											<i class="fa fa-check"  title="保存">保存</i>
										</button>
									</div>
								</div>
								<div class="portlet-body">
									<div class="tabbable">
										<div class="tab-content no-space">
											<div class="tab-pane active" id="tab_general">
												<div class="form-body">
													<div class="form-group">
														<label class="col-md-2 control-label">广告名称: <span
															class="required">*</span>
														</label>
														<div class="col-md-5">
															<input type="text" id="name" name="name"
																class="form-control tags medium" value="${data.name}" />
														</div>
													</div>
													<div class="form-group">
														<label class="col-md-2 control-label">广告链接: <span
															class="required">*</span>
														</label>
														<div class="col-md-5">
															<input type="text" id="url" name="url"
																class="form-control tags medium" value="${data.url}" />
																<h4 style="color:red">(注:链接为http或https开头)</h4>
														</div>
													</div>	
													<div class="form-group">
														<label class="col-md-2 control-label">直播名称:
														     <span class="required">*</span>
														</label>
														<div class="col-md-3">
															<select id="liveId" name="liveId" onchange="cklive()" class="form-control">
															<c:if test="${(roleid==0&&roleid!=''&&data.id!=null&&liveId!=0)||(roleid==0&&roleid!=''&&data.id==null&&liveId==0)||(roleid==0&&roleid!=''&&data.id!=null&&liveId==0)}">
																<option value="0" selected="selected">请选择</option>
																<c:forEach items="${datalists }" var="datalist">
																	<option value="${datalist.id }" <c:if test="${data.liveId==datalist.id}">selected="selected" </c:if>>${datalist.name }</option>
																</c:forEach>							
															</c:if>
															<c:if test="${(roleid==''&&data.id!=null&&liveId!=0)||(roleid==''&&data.id==null&&liveId==0)||(roleid==''&&data.id!=null&&liveId==0)}">
															<option value="0" selected="selected">请选择</option>
																<c:forEach items="${datalists }" var="datalist">
																	<option value="${datalist.id }" <c:if test="${data.liveId==datalist.id}">selected="selected" </c:if>>${datalist.name }</option>
																</c:forEach>							
															</c:if>
															<c:if test="${data.id==null&&liveId!=0}">
															<option value="0" selected="selected">请选择</option>
																<c:forEach items="${datalists }" var="datalist">
																	<option value="${datalist.id }" <c:if test="${liveId==datalist.id}">selected="selected" </c:if>>${datalist.name }</option>
																</c:forEach>							
															</c:if>
															</select>
														</div>
														<input type="hidden" id="liveName" name="liveName"  value="" />
													</div>
													<div class="form-group">
														<label class="col-md-2 control-label">广告类别:
														     <span class="required">*</span>
														</label>
														<div class="col-md-3">
															<select id="advertisingType" name="advertisingType" onchange="ckatype()" class="form-control">
																<c:if test="${roleid==0&&roleid!=''}">
																	<option value="0">请选择</option>
																	<c:if test="${data.advertisingType==null }">
																		 <option value="1">合作广告</option>
																		<%-- <option value="2">交流广告</option>--%>
																		<option value="3">合作广告2</option>
																	</c:if>
																	<c:if test="${data.advertisingType!=null}">
																	      <option value="1"
																	<c:if test="${data.advertisingType==1}">selected="selected" </c:if>>合作广告</option>
																	   <option value="3"
																	<c:if test="${data.advertisingType==3}">selected="selected" </c:if>>合作广告2</option>
																	</c:if>
																</c:if>
																<c:if test="${roleid!=0||roleid==''}">
																	<c:if test="${data.advertisingType==null }">
																		 <option value="1">合作广告</option>
																		 <option value="3">合作广告2</option>
																		<%-- <option value="2">交流广告</option>--%>
																	</c:if>
																	<c:if test="${data.advertisingType!=null}">
																	      <option value="1"
																	<c:if test="${data.advertisingType==1}">selected="selected" </c:if>>合作广告</option>
																	
																	   <option value="3"
																	<c:if test="${data.advertisingType==2}">selected="selected" </c:if>>合作广告2</option>
																	</c:if>
																</c:if>					
															</select>
														</div>
													</div>	
												<input type="hidden" id="imgUrl" name="imgUrl" class="form-control" value="${data.imgUrl}"/>                                         
                                                <div class="form-group">
                                                <label class="col-md-2 control-label">封面：</label>

                                                <div class="col-md-8">
                                                    <div class="fileinput fileinput-new" data-provides="fileinput">
                                                        <div class="fileinput-new thumbnail" style="width: 300px; height: 150px;">
                                                            <img src="${data.imgUrl}">
                                                        </div>
                                                        <div class="fileinput-preview fileinput-exists thumbnail"
                                                             style="max-width: 300px; max-height: 150px;">
                                                        </div>
                                                        <div>
                                                            <span class="btn default btn-file">
                                                                <span class="fileinput-new">选择图片</span>
                                                                <span class="fileinput-exists">修改图片</span>
                                                                <input type="file" id="file" name="file"/>
                                                            </span>
                                                            <a href="#" class="btn default fileinput-exists"
                                                               data-dismiss="fileinput">移除图片
                                                            </a>
                                                        </div>
                                                    </div>
                                                    <h4 style="color:red">(注:图片分辨率建议300x180)</h4>
                                                </div>
                                            </div>
                                            
                                           <!--   <div class="form-group">
												<label class="col-md-2 control-label">广告描述: </label>
												<div class="col-md-8">
													<input id="context" type="hidden" name="context">
													<script id="editor" type="text/plain" style="height:200px;">${data.context}</script>
												</div>
											</div>-->
											
											<div class="form-group">
														<label class="col-md-2 control-label">广告描述: <span
															class="required"></span>
														</label>
														<div class="col-md-5">
														    <textarea  class="form-control tags medium" rows="4" cols="50" id="context" name="context">${data.context}</textarea>
														</div>
											</div>
											</div>
											</div>
										</div>
									</div>
								</div>

								<div class="portlet-title">
									<div class="actions btn-set">
										<a href="javascript:history.go(-1);" class="btn default">
										  <i class="fa fa-angle-left" title="返回">返回</i>
										</a> 
										<a href="javascript:location.reload();" class="btn green">
										  <i class="fa fa-reply" title="重置">重置</i>
										</a>
										<button type="button" class="btn blue save" onclick="save()">
											<i class="fa fa-check"  title="保存">保存</i>
										</button>
									</div>
								</div>
							</div>
							<input type="hidden" id="id" name="id" value="${data.id}">
							<%--  <input type="hidden" id="image" name="image" class="form-control" value="${data.image}" />--%>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
<jsp:include page="../common/footer.jsp" />
<script type="text/javascript" src="${path}/assets/plugins/bootstrap-fileinput/bootstrap-fileinput.js"></script>
<script type="text/javascript" src="${path}/assets/plugins/jquery-inputmask/jquery.inputmask.bundle.min.js"></script>
<script type="text/javascript" src="${path}/assets/plugins/jquery.input-ip-address-control-1.0.min.js"></script>
<script type="text/javascript" src="${path}/assets/plugins/jquery.pwstrength.bootstrap/src/pwstrength.js"></script>
<script type="text/javascript" src="${path}/assets/scripts/biz/ajaxfileupload.js"></script>
<script type="text/javascript" src="${path}/assets/plugins/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="${path}/assets/plugins/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" src="${path}/assets/plugins/ueditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="${path}/layer/layer.js"></script>
<script>
		var editor;
		$(function() {
			editor = UE.getEditor('editor');
			var liveId=${liveId};
// 			if(liveId!=0){
// 				$("#liveId").attr("disabled","disabled");
// 			}
		});
		
		function cklive(){
			var liveId=$("#liveId").val();
			if(liveId=='0'){
				layer.alert("请选择直播间", {
	  		        icon: 2,
	  		        offset: 'middle',
	  		        time: 3000, 
	  		        skin: 'layui-layer-lan'
	  		    });
				return false;
			}else{
				return true;
			}
		}
		
		function ckatype(){
			var liveId=$("#advertisingType").val();
			if(liveId=='0'){
				layer.alert("广告类别一定要选", {
	  		        icon: 2,
	  		        offset: 'middle',
	  		        time: 3000, 
	  		        skin: 'layui-layer-lan'
	  		    });
				return false;
			}else{
				return true;
			}
		}
		
		function ckname(){
			var name=$("#name").val();
			if(name==null||name==""){
				layer.alert("请输入广告名称或是合作伙伴", {
	  		        icon: 2,
	  		        offset: 'middle',
	  		        time: 3000, 
	  		        skin: 'layui-layer-lan'
	  		    });
				return false;
			}else{
				return true;
			}
		}
		
		function ckurl(){
			var url=$("#url").val();
			if(url==null||url==""){
				layer.alert("链接不能为空", {
	  		        icon: 2,
	  		        offset: 'middle',
	  		        time: 3000, 
	  		        skin: 'layui-layer-lan'
	  		    });
				return false;
			}else{
				return true;
			}
		}
		
		function ckliveId(){
			var liveid=$("#liveId").val();
			if(liveid==null||liveid==""){
				layer.alert("直播间不能为空，若没有直播间请先去创建。", {
	  		        icon: 2,
	  		        offset: 'middle',
	  		        time: 3000, 
	  		        skin: 'layui-layer-lan'
	  		    });
				return false;
			}else{
				return true;
			}
		}
		function save(){
			//var context = UE.getEditor('editor').getContent();
			//$("#context").val(context);
			//$("#liveId").removeAttr("disabled"); 
			var liveName=$("#liveId").find("option:selected").text();
			var image=$("#imgUrl").val();	
			if(ckname()&&ckurl()&&cklive()&&ckatype()&&ckliveId()){
				if ($("#file").val() != null && $("#file").val() != "") {
					$.ajaxFileUpload({
						url : '${path}/conf/upload',
						async : false,
						secureuri : false,
						fileElementId : 'file',
						dataType : 'json',
						success : function(data, status) {
							if (data.statusCode == 200) {
								$("#imgUrl").val(data.uri);
								$("#liveName").val(liveName);
								$("#formid").submit();
								return;
							}else{
								layer.alert("糟糕！ 图片上传失败...", {
					  		        icon: 2,
					  		        offset: 'middle',
					  		        time: 3000, 
					  		        skin: 'layui-layer-lan'
					  		    });
							}
						}
					});
				}else{
					 if(image==null||image==""){
						    layer.alert("请选择一张图片进行上传", {
				  		        icon: 2,
				  		        offset: 'middle',
				  		        time: 3000, 
				  		        skin: 'layui-layer-lan'
				  		    });
						    return false;
						}else{
							$("#liveName").val(liveName);
							$("#formid").submit();		
						}
				}	
			}
		}
		//检测图片是否符合规范
		function checkTypes(id) {
			var File_box = document.getElementById(id);
			var extend = File_box.value.substring(File_box.value
					.lastIndexOf(".") + 1);
			if (extend == "jpg" || extend == "png" || extend == "jpeg"
					|| extend == "bmp" || extend == "gif") {
				return true;
			}
		}
</script>
</body>
</html>